package com.plusone.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BlogsController extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	@SuppressWarnings("static-access")
	public void doGet(HttpServletRequest request, HttpServletResponse response) {
		ServletContext context = getServletContext();
		String requestUrl = request.getRequestURL().toString();
		String url = null;
		if (requestUrl
				.indexOf("/blogs/Using-JDO-with-Google-AppEngine-Datastore") > -1) {
			url = "/view/blogs/Using-JDO-with-GAE.jsp";
		} else if (requestUrl
				.indexOf("/blogs/Google-AppEngine-Datastore-Summary") > -1) {
			url = "/view/blogs/gae-summary.jsp";
		} else {
			try {
				response.sendError(response.SC_BAD_REQUEST,
						"Valid url is /blogs/[blog-post]");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				// e.printStackTrace();
			}
		}

		RequestDispatcher dispatcher = context.getRequestDispatcher(url);
		try {
			dispatcher.forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
		}
	}

}
